/************************************************************************
 * File         :   cppTutorSTLList.cpp
 * Description  :   std :: list class definition 
 * Author       :   eLearning Business Unit
 * Company      :   ccplusplus.com
 * Date         :   created     11:57 16-06-2013
 *              :   revision    
 * Version      :   1.0.0
 * Notes        :
 *
 ************************************************************************/
 
#include "cppTutorSTLList.h"

// Log framework
#include "cppTutorLog.h"
extern CcppTutorLog Log;

using namespace std;

/////////////////////////////
// constructor / destructor
/////////////////////////////
CcppTutorSTLList :: CcppTutorSTLList () : m_bReturnStatus (true), m_nWeekDays (7), m_nTemp(0) {
    Log << "ENTER : CcppTutorSTLList :: CcppTutorSTLList()" << endl;
    Log << "EXIT  : CcppTutorSTLList :: CcppTutorSTLList()" << endl;
}

CcppTutorSTLList :: ~CcppTutorSTLList () {
    Log << "ENTER : CcppTutorSTLList :: ~CcppTutorSTLList()" << endl;
    Log << "EXIT  : CcppTutorSTLList :: ~CcppTutorSTLList()" << endl;
}

//-------------------------------------------------------------------
// Function     :   m_displayList
// Return Type  :   true/false
// Arguments    :   none
// Details      :   generic function to display the list
// Notes        :   
//-------------------------------------------------------------------
bool CcppTutorSTLList :: m_displayList () {
    Log << "ENTER : CcppTutorSTLMap :: m_displayList()" << endl;

    m_bReturnStatus = true;
    m_nTemp = 1;
    cout << "\nStandard Template library : list\n" << endl;
    cout << "\t-----------------------------------" << endl;
    cout << "\t S.No.                   Weekdays " << endl;
    cout << "\t-----------------------------------" << endl;
    for (strFirstList_it = strFirstList.begin (); strFirstList_it != strFirstList.end (); ++strFirstList_it) {
        cout << "\t [" << m_nTemp << "] \t\t\t " << *strFirstList_it << endl;
        ++ m_nTemp;
    }
    cout << "\t-----------------------------------" << endl;

    Log << "EXIT  : CcppTutorSTLMap :: m_displayList() [" << m_bReturnStatus << " : " << __LINE__ << "]"<< endl;
    return m_bReturnStatus;    
}

//-------------------------------------------------------------------
// Function     :   m_assignList
// Return Type  :   true/false
// Arguments    :   none
// Details      :   list :: assign
// Notes        :   
//-------------------------------------------------------------------
bool CcppTutorSTLList :: m_assignList () {
    Log << "ENTER : CcppTutorSTLMap :: m_assignList()" << endl;
    
    m_bReturnStatus = true;
    // create a list of 7 empty elements
    string strWeekDays;
    strFirstList.assign (7, "");

    m_displayList ();
    
    Log << "EXIT  : CcppTutorSTLMap :: m_assignList() [" << m_bReturnStatus << " : " << __LINE__ << "]"<< endl;
    return m_bReturnStatus;
}

//-------------------------------------------------------------------
// Function     :   m_push_backList
// Return Type  :   true/false
// Arguments    :   none
// Details      :   list :: push_back
// Notes        :   
//-------------------------------------------------------------------
bool CcppTutorSTLList :: m_push_backList () {
    Log << "ENTER : CcppTutorSTLMap :: m_push_backList()" << endl;

    m_bReturnStatus = true;
    initWeekDaysUsingVector ();

    for (m_nTemp = 1, strVec_it = strVec.begin(); m_nTemp <= m_nWeekDays, strVec_it != strVec.end(); ++ m_nTemp) {
        cout << "Pushing : '" << *strVec_it << "' in the list !" << endl;
        strFirstList.push_back (*strVec_it);
        ++ strVec_it;
    }
    m_displayList ();
    
    Log << "EXIT  : CcppTutorSTLMap :: m_push_backList() [" << m_bReturnStatus << " : " << __LINE__ << "]"<< endl;
    return m_bReturnStatus;    
}

//-------------------------------------------------------------------
// Function     :   m_clearList
// Return Type  :   true/false
// Arguments    :   none
// Details      :   list :: clear
// Notes        :   
//-------------------------------------------------------------------
bool CcppTutorSTLList :: m_clearList () {
    Log << "ENTER : CcppTutorSTLMap :: m_clearList()" << endl;
    
    m_bReturnStatus = true;
    m_displayList ();
    cout << "Removing all the elements from the list." << endl;
    strFirstList.clear ();
    m_displayList ();
    
    Log << "EXIT  : CcppTutorSTLMap :: m_clearList() [" << m_bReturnStatus << " : " << __LINE__ << "]"<< endl;
    return m_bReturnStatus;
}

//-------------------------------------------------------------------
// Function     :   m_emptyList
// Return Type  :   true if the list is empty; false if the list is not empty.
// Arguments    :   none
// Details      :   list :: empty
// Notes        :   
//-------------------------------------------------------------------
bool CcppTutorSTLList :: m_emptyList () {
    Log << "ENTER : CcppTutorSTLMap :: m_emptyList()" << endl;

    m_bReturnStatus = true;
    
    if (strFirstList.empty () == true) {
        cout << "list is empty" << endl;
    }
    else {
        cout << "list is not empty" << endl;
        m_bReturnStatus = false;
    }
    
    Log << "EXIT  : CcppTutorSTLMap :: m_emptyList() [" << m_bReturnStatus << " : " << __LINE__ << "]"<< endl;
    return m_bReturnStatus;    
}

//-------------------------------------------------------------------
// Function     :   m_eraseList
// Return Type  :   true if the list is empty; false if the list is not empty.
// Arguments    :   none
// Details      :   list :: empty
// Notes        :   
//-------------------------------------------------------------------
bool CcppTutorSTLList :: m_eraseList () {
    Log << "ENTER : CcppTutorSTLMap :: m_eraseList()" << endl;

    m_bReturnStatus = true;
    while (!strFirstList.empty()) {
        cout << "Erasing first element" << endl;
        strFirstList.erase (strFirstList.begin());
    }
    m_displayList ();
    
    Log << "EXIT  : CcppTutorSTLMap :: m_eraseList() [" << m_bReturnStatus << " : " << __LINE__ << "]"<< endl;
    return m_bReturnStatus;    
}

//-------------------------------------------------------------------
// Function     :   m_listDemo
// Return Type  :   true/false
// Arguments    :   none
// Details      :   public function for list operations
// Notes        :   
//-------------------------------------------------------------------
bool CcppTutorSTLList :: m_listDemo () {
    Log << "ENTER : CcppTutorSTLMap :: m_listDemo()" << endl;

    m_bReturnStatus = true;
    #ifdef STL_LIST_ASSIGN
    m_assignList ();
    #endif //STL_LIST_ASSIGN
    
    #ifdef STL_LIST_PUSH_BACK
    m_push_backList ();
    #endif //STL_LIST_PUSH_BACK

    #ifdef STL_LIST_EMPTY
    cout << "Checking whether list is empty of not : ";
    m_emptyList ();
    #endif //STL_LIST_EMPTY
        
    #ifdef STL_LIST_CLEAR
    m_clearList ();
    #endif //STL_LIST_CLEAR

    #ifdef STL_LIST_EMPTY
    cout << "Checking whether list is empty of not : ";
    m_emptyList ();
    #endif //STL_LIST_EMPTY
    
    #ifdef STL_LIST_ERASE
    m_eraseList ();
    #endif //STL_LIST_ERASE

    Log << "EXIT  : CcppTutorSTLMap :: m_listDemo() [" << m_bReturnStatus << " : " << __LINE__ << "]"<< endl;
    return m_bReturnStatus;    
}
